package com.suray.socket;

import com.suray.socket.core.SocketInstance;
import com.suray.socket.type.SocketType;

import java.io.IOException;

public interface SocketInterface {

    public static SocketInterface getInstance(Integer id) {
        SocketInterface socket = SocketInstance.get(id);

        return socket;
    }

    public static SocketInterface getInstance(String ip, int port, SocketType socketType) {
        SocketInterface socket = SocketInstance.getInstance(ip, port, socketType);

        return socket;
    }

    static void deleteSocket(SocketInterface socket) {
        SocketInstance.deleteSocket(socket);
    }

    /**
     * 发送数据
     *
     * @param data
     */
    public void sendData(byte[] data) throws IOException;

    /**
     * 接收数据
     *
     * @return 无数据时返回null
     */
    public byte[] recData();

    /**
     * 接收数据, 超时抛错
     *
     * @param time 超时时间, 10ms为单位
     * @return 无数据时返回null
     */
    public byte[] recData(int time) throws IOException;

    /**
     * 是否在线
     *
     * @return
     */
    public boolean isOnline();

    /**
     * 关闭连接
     *
     * @return
     */
    public boolean close();
}
